<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<script>
    function clearCookies() {
        alert("sssssss");
        document.forms[0].action="<%=request.getContextPath()%>/clearCookies";        
        document.forms[0].submit();
    }

    function writeCookies() {
        document.forms[0].action="<%=request.getContextPath()%>/writeCookies";
        document.forms[0].submit();
    }

    function clearValues() {
        document.forms[0].username.value = "";
        document.forms[0].password.value = "";
    }
</script>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        1) Write Cookies -> Goi servlet để add cookies<BR>
        2) Get Cokies -> Lấy dữ liệu từ cookies và set vào textboxes (sau khi gọi Write Cookies)<BR>
        3) Clear Cookies -> Xóa cookies bằng phương thức setMaxAge(0)<BR>
        NOTE: for testing purpose, we cant show password (use "text" instead of "password")<BR><BR>
        <form action="<%=request.getContextPath()%>/getCookies">
            <b>User name:</b><input type='text' name='username' value="${username}">
            <b>Password:</b><input type='text' name='password' value="${password}">
            <BR>
            <input type="text" value="333" name="test">
            <input type="submit" Value="Get Cokies">
            <input type="button" Value="Write Cookies" onclick="writeCookies()">
            <input type="button" Value="Clear Cookies" onclick="clearCookies()">
            <input type="button" value="Clear" onclick="clearValues()">
        </form>
        <hr>
        <font color="blue">${message}</font>
    </body>
</html>
